package cn.com.guage.dtm.stat.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.guage.dtm.common.annotation.Log;
import cn.com.guage.dtm.common.core.controller.BaseController;
import cn.com.guage.dtm.common.core.domain.AjaxResult;
import cn.com.guage.dtm.common.core.page.TableDataInfo;
import cn.com.guage.dtm.common.enums.BusinessType;
import cn.com.guage.dtm.common.utils.poi.ExcelUtil;
import cn.com.guage.dtm.stat.domain.StatDataExploreDetail;
import cn.com.guage.dtm.stat.service.IStatDataExploreDetailService;

/**
 * 数据探索详情Controller
 * 
 * @author yangdechao
 * @date 2021-07-22
 */
@Controller
@RequestMapping("/explore/exploreDetail")
public class StatDataExploreDetailController extends BaseController
{
    private String prefix = "explore/exploreDetail";

    @Autowired
    private IStatDataExploreDetailService statDataExploreDetailService;

    @RequiresPermissions("explore:exploreDetail:view")
    @GetMapping()
    public String exploreDetail()
    {
        return prefix + "/exploreDetail";
    }

    /**
     * 查询数据探索详情列表
     */
    @RequiresPermissions("explore:exploreDetail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StatDataExploreDetail statDataExploreDetail)
    {
        startPage();
        List<StatDataExploreDetail> list = statDataExploreDetailService.selectStatDataExploreDetailList(statDataExploreDetail);
        return getDataTable(list);
    }

    /**
     * 导出数据探索详情列表
     */
    @RequiresPermissions("explore:exploreDetail:export")
    @Log(title = "数据探索详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StatDataExploreDetail statDataExploreDetail)
    {
        List<StatDataExploreDetail> list = statDataExploreDetailService.selectStatDataExploreDetailList(statDataExploreDetail);
        ExcelUtil<StatDataExploreDetail> util = new ExcelUtil<StatDataExploreDetail>(StatDataExploreDetail.class);
        return util.exportExcel(list, "数据探索详情数据");
    }

    /**
     * 新增数据探索详情
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存数据探索详情
     */
    @RequiresPermissions("explore:exploreDetail:add")
    @Log(title = "数据探索详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StatDataExploreDetail statDataExploreDetail)
    {
        return toAjax(statDataExploreDetailService.insertStatDataExploreDetail(statDataExploreDetail));
    }

    /**
     * 修改数据探索详情
     */
    @GetMapping("/edit/{exploreDetailId}")
    public String edit(@PathVariable("exploreDetailId") Long exploreDetailId, ModelMap mmap)
    {
        StatDataExploreDetail statDataExploreDetail = statDataExploreDetailService.selectStatDataExploreDetailById(exploreDetailId);
        mmap.put("statDataExploreDetail", statDataExploreDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据探索详情
     */
    @RequiresPermissions("explore:exploreDetail:edit")
    @Log(title = "数据探索详情", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StatDataExploreDetail statDataExploreDetail)
    {
        return toAjax(statDataExploreDetailService.updateStatDataExploreDetail(statDataExploreDetail));
    }

    /**
     * 删除数据探索详情
     */
    @RequiresPermissions("explore:exploreDetail:remove")
    @Log(title = "数据探索详情", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(statDataExploreDetailService.deleteStatDataExploreDetailByIds(ids));
    }
    
    @PostMapping("/showExploreDetailByExploreId")
  	@ResponseBody
  	public TableDataInfo showExploreDetailByExploreId(StatDataExploreDetail statDataExploreDetail) {
    	StatDataExploreDetail queryParams = new StatDataExploreDetail();
  		queryParams.setExploreId(statDataExploreDetail.getExploreId());
  		startPage();
  		List<StatDataExploreDetail> list =statDataExploreDetailService.selectStatDataExploreDetailList(statDataExploreDetail);
  		return getDataTable(list);
  	}
}
